package org.btik.random_block;

import org.bukkit.Material;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author lustre
 * @since 2025/5/24 19:01
 */
public class MaterialUtil {
    static List<Material> materials = new ArrayList<Material>();

    static {
        Material[] values = Material.values();
        for (Material material : values) {
            if (!material.isBlock() && !material.isItem()) {
                continue;
            }
            if (material.data == Door.class || material.data == Wall.class || material.data == TrapDoor.class
                    || material.data == CommandBlock.class || material.data == StructureBlock.class || material.data == Waterlogged.class
                    || material == Material.WATER) {
                continue;
            }
            String name = material.name();
            if (name.contains("COPPER") || name.contains("CANDLE") || name.contains("SIGN")) {
                continue;
            }
            if (name.endsWith("BANNER")) {
                continue;
            }
            materials.add(material);
        }
    }

    static Random random = new Random();

    static int lastOffSet = 0;

    public static Material getRandomMaterial() {
        int index = random.nextInt(materials.size());
        Material material = materials.get((index + lastOffSet) % materials.size());
        lastOffSet = index;
        return material;
    }
}
